<?php

/**
 * This is the model class for table "tbl_company".
 *
 * The followings are the available columns in table 'tbl_company':
 * @property integer $id
 * @property string $title
 * @property string $address
 * @property string $phones
 * @property string $ur_address
 * @property string $contact_people
 * @property string $contact_phone
 * @property integer $is_active
 * @property string $date_created
 * @property string $info
 * @property integer $is_color
 * @property integer $type
 * @property integer $city
 */
class Company extends CActiveRecord
{

    public static $cities = array(
        0=>'Стерлитамак',
        1=>'Салават',
        2=>'Ишимбай'
    );

	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Company the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_company';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('title, address, phones, ur_address, contact_people, contact_phone', 'required'),
			array('is_active, is_color, type, city', 'numerical', 'integerOnly'=>true),
			array('title, address, phones, ur_address, contact_people, contact_phone', 'length', 'max'=>255),
			array('date_created, info', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, title, address, phones, ur_address, contact_people, contact_phone, is_active, date_created, info, is_color, type, city', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}



	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'title' => 'Title',
			'address' => 'Address',
			'phones' => 'Phones',
			'ur_address' => 'Ur Address',
			'contact_people' => 'Contact People',
			'contact_phone' => 'Contact Phone',
			'is_active' => 'Is Active',
			'date_created' => 'Date Created',
			'info' => 'Info',
			'is_color' => 'Is Color',
			'type' => 'Type',
			'city' => 'City',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('phones',$this->phones,true);
		$criteria->compare('ur_address',$this->ur_address,true);
		$criteria->compare('contact_people',$this->contact_people,true);
		$criteria->compare('contact_phone',$this->contact_phone,true);
		$criteria->compare('is_active',$this->is_active);
		$criteria->compare('date_created',$this->date_created,true);
		$criteria->compare('info',$this->info,true);
		$criteria->compare('is_color',$this->is_color);
		$criteria->compare('type',$this->type);
		$criteria->compare('city',$this->city);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}